package com.restaurant.application.bookingset.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class TimesData implements PickableBean {

    public static final String FN_STARTTIME = "startTime";
    public static final String FN_ENDTIME = "endTime";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_STARTTIME,
            FN_ENDTIME);
    
    private String startTime;
    private String endTime;

    public TimesData(String startTime, String endTime) {
        setStartTime(startTime);
        setEndTime(endTime);
    }

    public TimesData() {
    }

    public TimesData duplicate() {
        TimesData result = new TimesData();
        result.startTime = this.startTime;
        result.endTime = this.endTime;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String value) {
        this.startTime = value;
    }

    public TimesData withStartTime(String value) {
        setStartTime(value);
        return this;
    }

    public TimesData withStartTime(String value, String defaultValue) {
        setStartTime(value == null ? defaultValue : value);
        return this;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String value) {
        this.endTime = value;
    }

    public TimesData withEndTime(String value) {
        setEndTime(value);
        return this;
    }

    public TimesData withEndTime(String value, String defaultValue) {
        setEndTime(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "startTime":
                return getStartTime();
            case "endTime":
                return getEndTime();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof TimesData)) return false;
        return signature().equals(((TimesData) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean TimesData has no signature defined, no hash code or equals possible.");
    }
}
